package com.dalianbank.controller;


import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.dalianbank.pojo.DV;
import com.dalianbank.pojo.DVEO;
import com.dalianbank.pojo.TV;
import com.dalianbank.pojo.TVEO;
import com.dalianbank.pojo.UI;
import com.jfinal.core.Controller;

public class IndexPortal extends Controller {
	public void index(){
		String id=getPara("id");
		setAttr("id",id);
		render("full.html");
		
	}
	public void getUIJson(){
		List<TVEO> tveoList=new ArrayList<TVEO>();
		Map map=new HashMap();
		Map dveoMap=new HashMap();
		Map tveoMap=new HashMap();
		Map tvMap=new HashMap();
		List<TV> tvList=new ArrayList<TV>();
		String tvStr [];
		int id=getParaToInt("id");
		//String id=getPara("id");
		UI ui=UI.me.findById(id);
		String tvId=ui.getStr("tv_id");
		System.out.println(ui.getStr("tv_id"));
		DV dv=DV.me.findById(ui.getBigDecimal("dv_id"));
		List<DVEO> dveoList=DVEO.me.find("select * from vp.dv_eo a,vp.eo b,vp.DATA_TYPE c  where a.EO_ID=b.id  and c.id=a.DATA_ID and a.flag='0' and a.dv_id="+ui.getBigDecimal("dv_id")+"");
	    if(tvId.indexOf(",")>-1){
	    	tvStr=tvId.split(",");
	    	if(tvStr.length==2){
	    		tvList=TV.me.find("select * from vp.tv where id ='"+tvStr[0]+"'" +"or id='"+tvStr[1]+"'");
	    	}
	    	 
	    }else{
	    	tvList=TV.me.find("select * from vp.tv where id in('"+tvId.toString()+"')");
	    }
	    int i=0;
		for(TV tv:tvList){
			tvStr=tvId.split(",");
	    	if(tvStr.length==2){
	    		//tvList=TV.me.find("select * from vp.tv where id ='"+tvStr[0]+"'" +"or id='"+tvStr[1]+"'");
	    		;
	    		tveoList=TVEO.me.find("select * from vp.tv_eo a left join vp.DATA_TYPE b on  a.DATE_ID=b.id  left join vp.eo c on  a.EO_id=c.id where tv_id='"+tvStr[i]+"' and a.type='0' order by a.seq");
	    		tv.put("TVEONAME1",tveoList.get(0).getStr("EO_NAME"));
				tv.put("TVEONAME2",tveoList.get(1).getStr("EO_NAME"));
	    	
	    	}else{
	    		tveoList=TVEO.me.find("select * from vp.tv_eo a left join vp.DATA_TYPE b on  a.DATE_ID=b.id  left join vp.eo c on  a.EO_id=c.id where tv_id='"+tvId+"' and a.type='0' order by a.seq");
	    		tv.put("TVEONAME1",tveoList.get(0).getStr("EO_NAME"));
	    	}
			
		//	tveoList=TVEO.me.find("select * from vp.tv_eo  where tv_id='"+ui.getStr("tv_id")+"'");
			tv.put("EO",tveoList);
			if(tveoList.size()==2){
				
			}
		//	tv.put("TVEONAME1",tveoList.get(0).getStr("EO_NAME"));
		//	tv.put("TVEONAME2",tveoList.get(1).getStr("EO_NAME"));
			i++;
			
		}
		
		ui.put("TVSIZE",tvList.size());
		tvMap.put("TV", tvList);
		ui.put(tvMap);
		dveoMap.put("EO", dveoList);
		dv.put(dveoMap);
		map.put("DV",dv);
		ui.put("SERVICE","/search/searchCP");
	    ui.put(map);
		renderJson(ui);
	}
	
	public void login(){
		render("login.html");
	}
	
	public void getAllUI(){
		List<UI> uiList=new UI().me.find("select * from vp.ui where type='1' ");
		setAttr("uiList", uiList);
		render("index.html");
	
	}
	
	
}
